/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { expect } from '@jest/globals';
import * as fse from 'fs-extra';
import * as path from 'path';

import { initByStageEmptyApp, initExecuteCommand, runHvigor, } from '../../common/common';

describe('test make project pack.info', () => {
  test.concurrent('test stage make project pack.info and incremental', async () => {
    await initByStageEmptyApp(async (projectRoot) => {
      const commands = initExecuteCommand({
        mode: 'project',
        product: 'default',
        tasks: 'MakeProjectPackInfo',
        log: 'i'
      });

      // 第一次执行 expect Finish
      const result = runHvigor(projectRoot, commands);
      expect(result.stdout).toContain('Finished ::MakeProjectPackInfo...');
      expect(result.stdout).toContain('BUILD SUCCESSFUL');

      // 第二次执行 expect UpToDate
      const executeAgainResult = runHvigor(projectRoot, commands);
      expect(executeAgainResult.stdout).toContain('UP-TO-DATE ::MakeProjectPackInfo...');
      expect(executeAgainResult.stdout).toContain('BUILD SUCCESSFUL');

      // 删除输出
      const outputFile = path.resolve(projectRoot, 'entry/build/default/outputs/default/pack.info');
      fse.removeSync(outputFile);

      // 删除输出第一次执行 expect Finish
      const executeAgainResultAfterDelete = runHvigor(projectRoot, commands);
      expect(executeAgainResultAfterDelete.stdout).toContain('Finished ::MakeProjectPackInfo...');
      expect(executeAgainResultAfterDelete.stdout).toContain('BUILD SUCCESSFUL');
    });
  });
});
